using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace DataAccess
{
	/// <summary>
	/// Strongly-typed collection for the TblDeviceExpert class.
	/// </summary>
    [Serializable]
	public partial class TblDeviceExpertCollection : ActiveList<TblDeviceExpert, TblDeviceExpertCollection>
	{	   
		public TblDeviceExpertCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>TblDeviceExpertCollection</returns>
		public TblDeviceExpertCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                TblDeviceExpert o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the TblDeviceExpert table.
	/// </summary>
	[Serializable]
	public partial class TblDeviceExpert : ActiveRecord<TblDeviceExpert>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public TblDeviceExpert()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public TblDeviceExpert(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public TblDeviceExpert(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public TblDeviceExpert(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("TblDeviceExpert", TableType.Table, DataService.GetInstance("DataAccess"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int32;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = false;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarExpertId = new TableSchema.TableColumn(schema);
				colvarExpertId.ColumnName = "ExpertId";
				colvarExpertId.DataType = DbType.Int32;
				colvarExpertId.MaxLength = 0;
				colvarExpertId.AutoIncrement = false;
				colvarExpertId.IsNullable = true;
				colvarExpertId.IsPrimaryKey = false;
				colvarExpertId.IsForeignKey = false;
				colvarExpertId.IsReadOnly = false;
				colvarExpertId.DefaultSetting = @"";
				colvarExpertId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarExpertId);
				
				TableSchema.TableColumn colvarDateRequest = new TableSchema.TableColumn(schema);
				colvarDateRequest.ColumnName = "DateRequest";
				colvarDateRequest.DataType = DbType.DateTime;
				colvarDateRequest.MaxLength = 0;
				colvarDateRequest.AutoIncrement = false;
				colvarDateRequest.IsNullable = true;
				colvarDateRequest.IsPrimaryKey = false;
				colvarDateRequest.IsForeignKey = false;
				colvarDateRequest.IsReadOnly = false;
				colvarDateRequest.DefaultSetting = @"";
				colvarDateRequest.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateRequest);
				
				TableSchema.TableColumn colvarDeviceId = new TableSchema.TableColumn(schema);
				colvarDeviceId.ColumnName = "DeviceId";
				colvarDeviceId.DataType = DbType.Int32;
				colvarDeviceId.MaxLength = 0;
				colvarDeviceId.AutoIncrement = false;
				colvarDeviceId.IsNullable = true;
				colvarDeviceId.IsPrimaryKey = false;
				colvarDeviceId.IsForeignKey = false;
				colvarDeviceId.IsReadOnly = false;
				colvarDeviceId.DefaultSetting = @"";
				colvarDeviceId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDeviceId);
				
				TableSchema.TableColumn colvarCustId = new TableSchema.TableColumn(schema);
				colvarCustId.ColumnName = "CustId";
				colvarCustId.DataType = DbType.Int32;
				colvarCustId.MaxLength = 0;
				colvarCustId.AutoIncrement = false;
				colvarCustId.IsNullable = true;
				colvarCustId.IsPrimaryKey = false;
				colvarCustId.IsForeignKey = false;
				colvarCustId.IsReadOnly = false;
				colvarCustId.DefaultSetting = @"";
				colvarCustId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCustId);
				
				TableSchema.TableColumn colvarCount = new TableSchema.TableColumn(schema);
				colvarCount.ColumnName = "Count";
				colvarCount.DataType = DbType.Int32;
				colvarCount.MaxLength = 0;
				colvarCount.AutoIncrement = false;
				colvarCount.IsNullable = true;
				colvarCount.IsPrimaryKey = false;
				colvarCount.IsForeignKey = false;
				colvarCount.IsReadOnly = false;
				colvarCount.DefaultSetting = @"";
				colvarCount.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCount);
				
				TableSchema.TableColumn colvarExpPay = new TableSchema.TableColumn(schema);
				colvarExpPay.ColumnName = "ExpPay";
				colvarExpPay.DataType = DbType.String;
				colvarExpPay.MaxLength = -1;
				colvarExpPay.AutoIncrement = false;
				colvarExpPay.IsNullable = true;
				colvarExpPay.IsPrimaryKey = false;
				colvarExpPay.IsForeignKey = false;
				colvarExpPay.IsReadOnly = false;
				colvarExpPay.DefaultSetting = @"";
				colvarExpPay.ForeignKeyTableName = "";
				schema.Columns.Add(colvarExpPay);
				
				TableSchema.TableColumn colvarTotalPay = new TableSchema.TableColumn(schema);
				colvarTotalPay.ColumnName = "TotalPay";
				colvarTotalPay.DataType = DbType.String;
				colvarTotalPay.MaxLength = -1;
				colvarTotalPay.AutoIncrement = false;
				colvarTotalPay.IsNullable = true;
				colvarTotalPay.IsPrimaryKey = false;
				colvarTotalPay.IsForeignKey = false;
				colvarTotalPay.IsReadOnly = false;
				colvarTotalPay.DefaultSetting = @"";
				colvarTotalPay.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTotalPay);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["DataAccess"].AddSchema("TblDeviceExpert",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public int Id 
		{
			get { return GetColumnValue<int>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("ExpertId")]
		[Bindable(true)]
		public int? ExpertId 
		{
			get { return GetColumnValue<int?>(Columns.ExpertId); }
			set { SetColumnValue(Columns.ExpertId, value); }
		}
		  
		[XmlAttribute("DateRequest")]
		[Bindable(true)]
		public DateTime? DateRequest 
		{
			get { return GetColumnValue<DateTime?>(Columns.DateRequest); }
			set { SetColumnValue(Columns.DateRequest, value); }
		}
		  
		[XmlAttribute("DeviceId")]
		[Bindable(true)]
		public int? DeviceId 
		{
			get { return GetColumnValue<int?>(Columns.DeviceId); }
			set { SetColumnValue(Columns.DeviceId, value); }
		}
		  
		[XmlAttribute("CustId")]
		[Bindable(true)]
		public int? CustId 
		{
			get { return GetColumnValue<int?>(Columns.CustId); }
			set { SetColumnValue(Columns.CustId, value); }
		}
		  
		[XmlAttribute("Count")]
		[Bindable(true)]
		public int? Count 
		{
			get { return GetColumnValue<int?>(Columns.Count); }
			set { SetColumnValue(Columns.Count, value); }
		}
		  
		[XmlAttribute("ExpPay")]
		[Bindable(true)]
		public string ExpPay 
		{
			get { return GetColumnValue<string>(Columns.ExpPay); }
			set { SetColumnValue(Columns.ExpPay, value); }
		}
		  
		[XmlAttribute("TotalPay")]
		[Bindable(true)]
		public string TotalPay 
		{
			get { return GetColumnValue<string>(Columns.TotalPay); }
			set { SetColumnValue(Columns.TotalPay, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varId,int? varExpertId,DateTime? varDateRequest,int? varDeviceId,int? varCustId,int? varCount,string varExpPay,string varTotalPay)
		{
			TblDeviceExpert item = new TblDeviceExpert();
			
			item.Id = varId;
			
			item.ExpertId = varExpertId;
			
			item.DateRequest = varDateRequest;
			
			item.DeviceId = varDeviceId;
			
			item.CustId = varCustId;
			
			item.Count = varCount;
			
			item.ExpPay = varExpPay;
			
			item.TotalPay = varTotalPay;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varId,int? varExpertId,DateTime? varDateRequest,int? varDeviceId,int? varCustId,int? varCount,string varExpPay,string varTotalPay)
		{
			TblDeviceExpert item = new TblDeviceExpert();
			
				item.Id = varId;
			
				item.ExpertId = varExpertId;
			
				item.DateRequest = varDateRequest;
			
				item.DeviceId = varDeviceId;
			
				item.CustId = varCustId;
			
				item.Count = varCount;
			
				item.ExpPay = varExpPay;
			
				item.TotalPay = varTotalPay;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ExpertIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn DateRequestColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn DeviceIdColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn CustIdColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn CountColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn ExpPayColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn TotalPayColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string ExpertId = @"ExpertId";
			 public static string DateRequest = @"DateRequest";
			 public static string DeviceId = @"DeviceId";
			 public static string CustId = @"CustId";
			 public static string Count = @"Count";
			 public static string ExpPay = @"ExpPay";
			 public static string TotalPay = @"TotalPay";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
